package wpRelations;

import java.util.ArrayList;
import java.util.Iterator;

import processing.core.PApplet;

public class wHub {
	wArticle core;
	PApplet parent;
	ArrayList<wArticle> links, backLinks;
	ArrayList<wCategory> superCategories,subCategories,subPages;
	
	public wHub(PApplet theParent, wArticle theCore) {
		parent = theParent;
		core = theCore;
	}
	
	public wHub(PApplet theParent, String theCoreName) {
		parent = theParent;
		core = new wArticle(parent, theCoreName);
	}

	public void init() {
		links = core.getLinks();
		backLinks = core.getBackLinks();
		superCategories = core.getCategories();
		//TODO: subCategories???
		for (int i = 0; i < superCategories.size(); i++) {
			System.out.println("Getting subCategories / pages for superCategory nr. " + (i+1) + " out of " + superCategories.size());
			superCategories.get(i).setSubCatsPages();
		}
		System.out.println("Got all subCategories / pages.");
	}
	
	public void printContents () {
	    Iterator itr = links.iterator();
	    System.out.println("printing links:");
	    while(itr.hasNext()) {
	    	String s = itr.next().toString();
	    	System.out.println("*link: " + s);
	    }
	    itr = backLinks.iterator();
	    System.out.println("printing backLinks:");
	    while(itr.hasNext()) {
	    	String s = itr.next().toString();
	    	System.out.println("*backLink: " + s);
	    }
	    itr = superCategories.iterator();
	    System.out.println("printing superCategories:");
	    while(itr.hasNext()) {
	    	String s = itr.next().toString();
	    	System.out.println("*superCategory: " + s);
	    }
	    System.out.println("printing subCategories:");
	   for (int i = 0; i < superCategories.size(); i++) {
			itr = superCategories.get(i).getSubCats().iterator();
			while(itr.hasNext()) {   
			String s = itr.next().toString();
	    	System.out.println("*superCategory: " + superCategories.get(i).toString() + " / subCategory: " + s);
			}
		}
	    
	   System.out.println("printing pages:");
	   for (int i = 0; i < superCategories.size(); i++) {
			itr = superCategories.get(i).getSubPages().iterator();
			while(itr.hasNext()) {   
			String s = itr.next().toString();
	    	System.out.println("*superCategory: " + superCategories.get(i).toString() + " / page: " + s);
			}
		}
	    
	    
	}
}
